package com.moxiao.yfjh.module.blind.dal.mysql.equity;

import com.moxiao.yfjh.module.blind.controller.admin.equity.vo.MemberEquityExportReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.equity.vo.MemberEquityPageReqVO;
import java.util.*;

import com.moxiao.yfjh.framework.common.pojo.PageResult;
import com.moxiao.yfjh.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.moxiao.yfjh.framework.mybatis.core.mapper.BaseMapperX;
import com.moxiao.yfjh.module.blind.dal.dataobject.equity.MemberEquityDO;
import org.apache.ibatis.annotations.Mapper;
import com.moxiao.yfjh.module.blind.controller.admin.equity.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 相亲会员权益 Mapper
 *
 * @author mx
 */
@Mapper
public interface MemberEquityMapper extends BaseMapperX<MemberEquityDO> {

    default PageResult<MemberEquityDO> selectPage(MemberEquityPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MemberEquityDO>()
                .eqIfPresent(MemberEquityDO::getUserId, reqVO.getUserId())
                .likeIfPresent(MemberEquityDO::getEquityName, reqVO.getEquityName())
                .eqIfPresent(MemberEquityDO::getSceneId, reqVO.getSceneId())
                .eqIfPresent(MemberEquityDO::getUsedBy, reqVO.getUsedBy())
                .eqIfPresent(MemberEquityDO::getRemainNum, reqVO.getRemainNum())
                .eqIfPresent(MemberEquityDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(MemberEquityDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MemberEquityDO::getId));
    }

    default List<MemberEquityDO> selectList(MemberEquityExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<MemberEquityDO>()
                .eqIfPresent(MemberEquityDO::getUserId, reqVO.getUserId())
                .likeIfPresent(MemberEquityDO::getEquityName, reqVO.getEquityName())
                .eqIfPresent(MemberEquityDO::getSceneId, reqVO.getSceneId())
                .eqIfPresent(MemberEquityDO::getUsedBy, reqVO.getUsedBy())
                .eqIfPresent(MemberEquityDO::getRemainNum, reqVO.getRemainNum())
                .eqIfPresent(MemberEquityDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(MemberEquityDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MemberEquityDO::getId));
    }


    @Select("select count(*) num from blind_member_equity where user_id = #{userId} and equity_name = #{equityName} and create_time between #{firstDayOfMonth} and #{lastDayOfMonth}")
    Long getMemberEquity(@Param("userId") Long userId
                                        ,@Param("equityName") String equityName
                                                ,@Param("firstDayOfMonth") Date firstDayOfMonth
                                                                        ,@Param("lastDayOfMonth") Date lastDayOfMonth);

}
